﻿namespace JxcLite.Repositories;

class HomeRepository
{
    internal static Task<int> GetBillCountAsync(Database db, string type)
    {
        var sql = "select count(*) from JxBillHead where CompNo=@CompNo and Type=@type";
        return db.ScalarAsync<int>(sql, new { db.User.CompNo, type });
    }

    internal static Task<int> GetBillCountAsync(Database db, string type, DateTime date)
    {
        var day = date.ToString("yyyy-MM-dd");
        var sql = $"select count(1) from JxBillHead where CompNo=@CompNo and Type=@type and BillDate between '{day} 00:00:00' and '{day} 23:59:59'";
        if (db.DatabaseType == DatabaseType.Access)
            sql = sql.Replace("'", "#");
        return db.ScalarAsync<int>(sql, new { db.User.CompNo, type });
    }
}